/**
 * zmn文章模块-文章编辑
 * 文件命名格式：zmn.模块.表/功能.jas
 * @author duanzuocai
 * @since 2018/10/22
 */
layui.define(['form', 'layedit'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;

    form.render(null, "zmn-form");
    zmnLayUtil.layFormVerify(form);

    // 提交
    form.on('submit(zmn-form-submit)', function(obj){
        var openId = layer.open({type: 3});
        var data = obj.field;
        var url = "/conf/cancel/category/addEdit.action";

        $.ajax({
            async: false,
            type: "POST", url: url,
            contentType: "application/json", dataType: "json", data: JSON.stringify(data),
            success:function(result) {
                layer.close(openId);
                if(result.status == 200) {
                    layer.msg(result.message,{time: 1000},()=>{
                        zmnLayUtil.closeThisIframe(parent);
                        parent.location.reload();
                    });
                } else {
                    layer.msg(result.message, {"icon": 2});
                }


            },
            error:function(XMLHttpRequest, textStatus, errorThrown){
                layer.close(openId);
            }
        })
        return false;
    });
    layui.$("#cancleBtn").click(function () {
        let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭
        return false;
    });

    //对外暴露的接口
    exports('oms_conf_cancel_category_detail', {});
});
